<?php

class ContentListElement extends UnderscoreGetters implements IContentListElement
{
	
	protected $photo;
	/**
	 * Id of element.
	 * @var string
	 */
	protected $id;
	
	/**
	 * Name of element.
	 * @var string
	 */
	protected $name;

	/**
	 * Description of element.
	 * @var string
	 */
	protected $description;

	/**
	 * Target url.
	 * @var string
	 */
	protected $url;


	/**
	 * Rating for element
	 * @var string
	 */
	protected $rating;
	
	protected $text;



	/**
	 * Set base object for use in call.
	 *
	 * @param mixed $object
	 * @return ContentListElement
	 */
	public function __construct($object = null)
	{
		//$this->_object = $object;
	}

	/**
	 * Create new ContentListElement by any class implemented IContentListElementProvider. !! Deprecated, use fromProvider(), which do the same things but sounds better :) !!
	 * Also store base object inside.
	 *
	 * @param IContentListElementProvider $row
	 * @param string Abstract type of ContentListElement
	 * @return ContentListElement
	 */
	public static function fromRow($row, $type = null)
	{
		return self::fromProvider($row, $type);
	}

	/**
	 * Create new ContentListElement by any class implemented IContentListElementProvider.
	 * Also store base object inside.
	 *
	 * @param IContentListElementProvider $provider
	 * @param string Abstract type of ContentListElement
	 * @return ContentListElement
	 */
	public static function fromProvider($provider, $type = null) {
		if (!$provider instanceof IContentListElementProvider) {
			throw new Exception('Intefrace IContentListElementProvider not implemented');
		}

		$element = $provider->getContentListElement($type);
		if ($element) {
			if ($provider instanceof ContentlistElementRow)
				$element->_object = $provider->parent_row;
			else
				$element->_object = $provider;
			return $element;
		} else return false;
	}

	public static function fromRowset($rowset, $params = array())
	{
		//var_dump($rowset);
		//$rowset = new Zend_Db_Table_Rowset();
		if (!$rowset instanceof ContentlistElementRowset) {
			$peer = call_user_func(array($rowset->getTableClass(), 'getInstance'));
			if ($peer instanceof Db_Peer) {
				$list = $peer->getContentList($rowset, $params);
			}
		} else {
			$list = $rowset->getContentList($params);
		}
		if ($list) {
			return $list;
		}
		return false;
	}
	
	public function toArray() {
		return $this->__toArray();
	}
	
	public function __toArray() {
		list($l, $name) = explode('_', get_class($this), 2);
		$name = strtolower($name);
		
		return array($name => $this);
	}
	

}